import { CHANGE_HOME_LIST, DEL_HOME_LIST } from './homeActiveTypes';

let defaultState = {
    homeList: []
}
export default (state = defaultState, action) => {
    // console.log(action);
    if (action.type === CHANGE_HOME_LIST) {
        let initState = JSON.parse(JSON.stringify(state));
        initState.homeList = action.value;
        return initState;
    }
    if (action.type === DEL_HOME_LIST) {
        let initState = JSON.parse(JSON.stringify(state));
        initState.homeList.items.forEach((item, index) => {
            if (item.restaurant.id === action.value) {
                initState.homeList.items.splice(index, 1)
            }
        })
        return initState;
    }
    return state;
}